package com.shiliao.app.activity.index.presenter;

import android.text.TextUtils;

import com.shiliao.app.activity.index.service.ISearchService;
import com.shiliao.app.activity.index.service.impl.SearchImpl;
import com.shiliao.app.activity.index.view.SerachView;
import com.shiliao.app.utils.YMServerUtil;
import com.yimei.framework.mvp.presenter.IBasePresenter;
import com.yimei.framework.network.ICallBack;
import com.yimei.framework.util.LogUtil;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by yinzhiqiang on 2017/10/12.
 */

public class SerachPresenter extends IBasePresenter<ISearchService> {
    private ISearchService searchService;
    private SerachView serachView;

    public SerachPresenter(SerachView serachView) {
        this.serachView = serachView;
        searchService = new SearchImpl();
        setService(searchService);
    }

    public void requestSerach(String serachKey, String userId) {
        Map map = new HashMap();
        if (!TextUtils.isEmpty(serachKey)) {
            map.put("keyword", serachKey);
        }
        if (!TextUtils.isEmpty(userId)) {
            map.put("user_id", userId);
        }
        searchService.requestSreach(YMServerUtil.ACTION_SREACH_ARTICLE, map, new ICallBack() {
            @Override
            public void onSuccess(int statusCode, Object result) {
                LogUtil.e("yzq", result.toString());
                serachView.loadSerach(result.toString());
            }

            @Override
            public void onFail(int statusCode, Object result) {
                LogUtil.e("yzq", result.toString());
                serachView.loadSerach(result.toString());
            }
        });
    }

    public void requestProble(String serachKey, String userId) {
        Map map = new HashMap();
        if (!TextUtils.isEmpty(serachKey)) {
            map.put("keyword", serachKey);
        }
        if (!TextUtils.isEmpty(userId)) {
            map.put("user_id", userId);
        }
        searchService.requestSreach(YMServerUtil.ACTION_SREACH_PROBLE, map, new ICallBack() {
            @Override
            public void onSuccess(int statusCode, Object result) {
                LogUtil.e("yzq", result.toString());
                serachView.loadSerach(result.toString());
            }

            @Override
            public void onFail(int statusCode, Object result) {
                LogUtil.e("yzq", result.toString());
                serachView.loadSerach(result.toString());
            }
        });
    }
}
